﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using PiscoSourDominio;
using PiscoSourSOAPRestServices.Persistencia;
using Dapper;
namespace PiscoSourRESTServices.Persistencia
{
    public class PlatoDAO
    {
        public Plato ObtenerPlato(string codigo)
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                const string sqlQuery = "select * from psr_plato where intCodPlato=@intCodPlato";
                var plato = sqlConnection.Query<Plato>(sqlQuery, new { intCodPlato = codigo }).SingleOrDefault<Plato>();

                sqlConnection.Close();

                return plato;
            }
        }

        public IEnumerable<Plato> ListarOrdenes()
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                var sqlQuery = string.Format(@"Select * from psr_plato");
                var result = sqlConnection.Query<Plato>(sqlQuery);
                sqlConnection.Close();
                return result;
            }
        }     
    }
}